package com.szgr.baoyin.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.szgr.baoyin.MainActivity;
import com.szgr.baoyin.R;
import com.szgr.baoyin.pay.PaySuccessActivity;
import com.szgr.baoyin.utils.Constant;

public class WebActivity extends Activity {

    private String html;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);

        initView();
    }

    private void initView() {
        Intent intent = getIntent();
        if(intent != null && intent.hasExtra("html")) {
            html = intent.getStringExtra("html");
        }
        WebView webView = (WebView) findViewById(R.id.webView);
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                System.out.println("----url change---->" + url);
                if(url.startsWith(Constant.URL_HEAD + "/mobile/api/payment/alipay/call_back_url.php")){
                    Intent intent1 = new Intent(WebActivity.this,PaySuccessActivity.class);
                    intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent1);
                }
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
        webView.getSettings().setDefaultTextEncodingName("UTF-8");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadDataWithBaseURL("", html, "text/html", "UTF-8", "");
    }
}
